package com.onpositive.units;

import org.w3c.dom.Element;

import com.onpositive.knowledge.model.values.IHasValue;

public class ParsedString extends ParsedTerm {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2986840892222870693L;



	public static final String ID = "string" ;
	
	private String value ;
	
	public ParsedString( String value, String comment ){
		super(comment) ;
		this.value = value ;
	}
	
	public ParsedString( ParsedValue pv, String comment )
	{
		super( comment ) ;		
		ParsedString other = (ParsedString) pv ;
		this.value = other.value ;		
	}
	
	public ParsedString( Element element ){
		super(element) ;
		this.value = element.getAttribute("value") ;
	}
	
	public ParsedString(ParsedString other, Object value, String comment)
	{
		super( comment ) ;
		this.value = (String) value ;
	}

	@Override
	public Object value() {
		return this.value;
	}

	@Override
	public Object describer() {
		return String.class ;
	}

	@Override
	public String getId() {
		return ID ;
	}

	@Override
	public String getValueAsString() {
		return this.value;
	}

	@Override
	public void setValue(Object obj) {
		this.value = (String)obj ;
		
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((value == null) ? 0 : value.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ParsedString other = (ParsedString) obj;
		if (value == null) {
			if (other.value != null)
				return false;
		} else if (!value.equals(other.value))
			return false;
		return true;
	}

	@Override
	public IHasValue clone(Object value, String comment) {
		if(!(value instanceof String))
			return null ;
		if( comment == null )
			comment = this.getComment() ;
		return new ParsedString( this, value, comment );
	}

}
